package com.example.mymvplibrary.adapter;


import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;


public class BaseViewHolder extends RecyclerView.ViewHolder{
    private View rootView;
    private SparseArray<View>sparseArray;
    public BaseViewHolder(View itemView) {
        super(itemView);
        rootView=itemView;
        sparseArray=new SparseArray<>();
    }

    //找控件
    public <T extends View> T getView(int viewId){
        if(sparseArray.get(viewId)==null){
            View viewById = rootView.findViewById(viewId);
            sparseArray.put(viewId,viewById);
        }
        return (T) sparseArray.get(viewId);
    }

    public void setText(int textViewId,String text){
        TextView textView = getView(textViewId);
        textView.setText(text);
    }
}
